package business;
import java.util.ArrayList;

import data.Job;


/**
 * Schedule class holds collections for scheduled jobs, 
 * unscheduled jobs, and past jobs.
 * users of these collection must specify which type of
 * job to add into which list.
 * @author Faiz
 * @version 2/23/11
 */
public class Schedule {
	
	/**
	 * List of scheduled jobs 
	 */
	private ArrayList<Job>  scheduledJobs;
	/**
	 * List of unscheduled jobs 
	 */
	private ArrayList<Job> unscheduledJobs;	
	/**
	 * Current date time of when the schedule method 
	 * has been instantiated 
	 */
	//private Date currentDate;
	
	/**
	 * Initializes the object. Initializes all lists
	 * and updates list of disabled jobs 
	 */
	public Schedule() {
		scheduledJobs = new ArrayList<Job>();
		unscheduledJobs = new ArrayList<Job>();
	}
		
	/**
	 * Adds a shceduled job to the scheduled
	 * job list. if job is not scheduled then it 
	 * will not be added
	 * @param newJob job to be added
	 */
	private void addScheduledJob(Job newJob) {
		if(newJob.getVerified() && !scheduledJobs.contains(newJob)) {
			scheduledJobs.add(newJob);
		}
	}
	
	/**
	 * Adds an unscheduled job to the unscheduled 
	 * job list. if the job is not unscheduled it 
	 * will not be added
	 * @param newJob job to be added
	 */
	private void addUnscheduledJob(Job newJob) {			// add to UML
		if(!newJob.getVerified() && !unscheduledJobs.contains(newJob)) {
			unscheduledJobs.add(newJob);
		}
	}
	
	/**
	 * Removes an unscheduled job from the unscheduled
	 * job list. if the job is not in the list then 
	 * it will not be removed
	 * @param remove
	 */
	public void removeUnscheduledJob(Job remove) {
		if(unscheduledJobs.contains(remove)) {
			unscheduledJobs.remove(remove);
		}
	}	
	
		
	/**
	 * Returns an arraylist of unscheduled
	 * jobs
	 * @return an arraylist of the unscheduled jobs
	 * waiting to be scheduled
	 */
	public ArrayList<Job> viewUnscheduledJob() {
		return unscheduledJobs;
	}
	
	/**
	 * Returns the arraylist of scheduled jobs
	 * @return an arraylist of scheduled jobs
	 */
	public ArrayList<Job> viewScheduledJob() {
		return scheduledJobs;
	}
	
	/**
	 * Method should return past jobs.
	 * Not implemented since not part of a use case
	 * @return an arraylist of past jobs
	 */
	public ArrayList<Job> viewPastJobs() {
		return null;
	}
	
	/**
	 * Allows addition of a job. Schedule class checks which list it belongs into
	 * @param newJob the job to be added
	 */
	public void addJob(Job newJob) {
		this.addScheduledJob(newJob);
		this.addUnscheduledJob(newJob);
	}
	
	/**
	 * Allows addition of a job. Schedule class checks which list it belongs into
	 * @param newJobs the job to be added in a list form
	 */
	public void addJob(Job... newJobs) {
		for(Job theJob : newJobs) {
			this.addScheduledJob(theJob);
			this.addUnscheduledJob(theJob);
		}
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		String out = "";
		for (Job theJob : scheduledJobs) {
			out += theJob.toString();
		}
		for (Job theJob : unscheduledJobs) {
			out += theJob.toString();
		}
		return out;
	}
}